package cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistnj;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistnj.vo.DpWestListNjPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistnj.vo.DpWestListNjRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.dpitem.dpwestlistnj.vo.DpWestListNjSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.dplist.DpWestListNjDO;
import cn.iocoder.yudao.module.erp.service.dpwest.DpWestListNjService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.List;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


@Tag(name = "管理后台 - 南疆口岸仓西线清单")
@RestController
@RequestMapping("/erp/dp-west-list-nj")
@Validated
public class DpWestListNjController {

    @Resource
    private DpWestListNjService dpWestListNjService;

    @PostMapping("/create")
    @Operation(summary = "创建南疆口岸仓西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-nj:create')")
    public CommonResult<Long> createDpWestListNj(@Valid @RequestBody DpWestListNjSaveReqVO createReqVO) {
        return success(dpWestListNjService.createDpWestListNj(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新南疆口岸仓西线清单")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-nj:update')")
    public CommonResult<Boolean> updateDpWestListNj(@Valid @RequestBody DpWestListNjSaveReqVO updateReqVO) {
        dpWestListNjService.updateDpWestListNj(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除南疆口岸仓西线清单")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-nj:delete')")
    public CommonResult<Boolean> deleteDpWestListNj(@RequestParam("id") Long id) {
        dpWestListNjService.deleteDpWestListNj(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得南疆口岸仓西线清单")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-nj:query')")
    public CommonResult<DpWestListNjRespVO> getDpWestListNj(@RequestParam("id") Long id) {
        DpWestListNjDO dpWestListNj = dpWestListNjService.getDpWestListNj(id);
        return success(BeanUtils.toBean(dpWestListNj, DpWestListNjRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得南疆口岸仓西线清单分页")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-nj:query')")
    public CommonResult<PageResult<DpWestListNjRespVO>> getDpWestListNjPage(@Valid DpWestListNjPageReqVO pageReqVO) {
        PageResult<DpWestListNjDO> pageResult = dpWestListNjService.getDpWestListNjPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DpWestListNjRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出南疆口岸仓西线清单 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:dp-west-list-nj:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDpWestListNjExcel(@Valid DpWestListNjPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DpWestListNjDO> list = dpWestListNjService.getDpWestListNjPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "南疆口岸仓西线清单.xls", "数据", DpWestListNjRespVO.class,
                        BeanUtils.toBean(list, DpWestListNjRespVO.class));
    }

}